﻿/******************************************************************
** 文件名:T116_GoodClassProperty_ValueDAL.cs
** Copyright (c) 
** 创建人:佟礼
** 日 期:2012-07-10 15:53:44
** 描 述:数据操作类
********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Data;
using Enter.DataProxy.DbConnector;
using Enter.Entity;
using Enter.DataProxy.Mail.Base;
using Enter.Config;
namespace Enter.DataProxy.Mail
{
    /// <summary>
    /// 数据操作类：T116_GoodClassProperty_ValueManager
    /// </summary>
    public class T116_GoodClassProperty_ValueManager : DataProxyManager, IT116_GoodClassProperty_ValueManager
    {
        public T116_GoodClassProperty_ValueManager() :
            base(ProxyProvider.ConfigurationName, ProxyProvider.ConfiruationDbName) { }
        #region 插入记录
        /// <summary>
        /// 插入记录
        /// </summary>
        /// <returns></returns>
        public int Insert(T116_GoodClassProperty_ValueEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            var db = base.CreateDbWriter();
            strSql.Append("INSERT INTO T116_GoodClassProperty_Value");
            strSql.Append("(VNO,PNo,VName,icon,Weight,HitCount,Descr,Status)");
            strSql.Append(" values ");
            strSql.Append("(@VNO,@PNo,@VName,@icon,@Weight,@HitCount,@Descr,@Status)");
            ParameterCollection parameters = CreateParameter();
            parameters.Append("VNO", model.VNO, DbType.String);
            parameters.Append("PNo", model.PNo, DbType.String);
            parameters.Append("VName", model.VName, DbType.String);
            parameters.Append("icon", model.icon, DbType.String);
            parameters.Append("Weight", model.Weight, DbType.Int32);
            parameters.Append("HitCount", model.HitCount, DbType.Int32);
            parameters.Append("Descr", model.Descr, DbType.String);
            parameters.Append("Status", model.Status, DbType.Int32);
            return db.ExecuteNonQuery(strSql.ToString(), parameters);
        }
        #endregion

        #region 更新数据
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <returns></returns>
        public int Update(T116_GoodClassProperty_ValueEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            var db = base.CreateDbWriter();
            strSql.Append("UPDATE T116_GoodClassProperty_Value SET ");
            strSql.Append("VNO=@VNO,PNo=@PNo,VName=@VName,icon=@icon,Weight=@Weight,HitCount=@HitCount,Descr=@Descr,Status=@Status");
            strSql.Append(" WHERE VID=@VID");
            ParameterCollection parameters = CreateParameter();
            parameters.Append("VID", model.VID, DbType.Int32);
            parameters.Append("VNO", model.VNO, DbType.String);
            parameters.Append("PNo", model.PNo, DbType.String);
            parameters.Append("VName", model.VName, DbType.String);
            parameters.Append("icon", model.icon, DbType.String);
            parameters.Append("Weight", model.Weight, DbType.Int32);
            parameters.Append("HitCount", model.HitCount, DbType.Int32);
            parameters.Append("Descr", model.Descr, DbType.String);
            parameters.Append("Status", model.Status, DbType.Int32);
            return db.ExecuteNonQuery(strSql.ToString(), parameters);
        }
        #endregion

        #region IEntityFacade 成员
        /// <summary>
        /// 填充数据
        /// </summary>
        /// <param name="reader"></param>
        public T116_GoodClassProperty_ValueEntity FillDetailWithReader(IDataReader reader)
        {
            T116_GoodClassProperty_ValueEntity model = new T116_GoodClassProperty_ValueEntity();
            if (reader["VID"] != DBNull.Value)
                model.VID = (int)reader["VID"];
            if (reader["VNO"] != DBNull.Value)
                model.VNO = (string)reader["VNO"];
            if (reader["PNo"] != DBNull.Value)
                model.PNo = (string)reader["PNo"];
            if (reader["VName"] != DBNull.Value)
                model.VName = (string)reader["VName"];
            if (reader["icon"] != DBNull.Value)
                model.icon = (string)reader["icon"];
            if (reader["Weight"] != DBNull.Value)
                model.Weight = (int)reader["Weight"];
            if (reader["HitCount"] != DBNull.Value)
                model.HitCount = (int)reader["HitCount"];
            if (reader["Descr"] != DBNull.Value)
                model.Descr = (string)reader["Descr"];
            if (reader["Status"] != DBNull.Value)
                model.Status = (EnumStatus)(byte)reader["Status"];
            return model;
        }
        #endregion

        #region 根据VID获取一个对象
        public T116_GoodClassProperty_ValueEntity GetObjectByVID(int VID)
        {
            string sql = "SELECT TOP 1 * FROM T116_GoodClassProperty_Value  WHERE VID=@VID";
            var db = base.CreateDbReader();
            ParameterCollection parameters = CreateParameter();
            parameters.Append("VID", VID, DbType.Int32);
            try
            {
                IDataReader reader = db.ExecuteReader(sql, parameters);
                if (reader.Read())
                {
                    return this.FillDetailWithReader(reader);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return null;
        }
        #endregion

        #region 删除数据
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns></returns>
        public int Delete(int VID)
        {
            var db = base.CreateDbWriter();
            string strSql = "DELETE T116_GoodClassProperty_Value WHERE VID=@VID";
            ParameterCollection parameters = CreateParameter();
            parameters.Append("VID", VID);
            return db.ExecuteNonQuery(strSql.ToString(), parameters);
        }
        #endregion

        #region 数据集
        public IList<T116_GoodClassProperty_ValueEntity> ShowList()
        {
            var db = base.CreateDbReader();
            string strSql = "SELECT  * FROM T116_GoodClassProperty_Value";
            IList<T116_GoodClassProperty_ValueEntity> result = null;
            result = db.Execute<T116_GoodClassProperty_ValueEntity>(strSql);
            return result;
        }
        public IList<T116_GoodClassProperty_ValueEntity> GetPrpertyValue(string PNo)
        {
            var db = base.CreateDbReader();
            string strSql = "SELECT  * FROM T116_GoodClassProperty_Value where Status=@Status and PNo=@PNo";
            IList<T116_GoodClassProperty_ValueEntity> result = null;
            ParameterCollection parameters = CreateParameter();
            parameters.Append("PNo", PNo, DbType.String);
            parameters.Append("Status", EnumStatus.Valid,DbType.Int32);
            result = db.Execute<T116_GoodClassProperty_ValueEntity>(strSql, parameters);
            return result;
        }
        #endregion

        #region 数据集
        public DataTable ShowTable()
        {
            var db = base.CreateDbReader();
            string strSql = "SELECT  * FROM T116_GoodClassProperty_Value";
            return db.ExecuteDataSet(strSql.ToString()).Tables[0];
        }
        #endregion

        #region 分页数据集
        public DataTable ShowTable(PageEntity entity, out int totalPages, out int totalCount)
        {
            BaseManager manager = new BaseManager();
            entity.tbName = "T116_GoodClassProperty_Value";
            entity.PKey = "VID";
            entity.Orderby = "VID desc";
            DataTable dt = manager.GetTable(entity);
            totalPages = entity.TotalPages;
            totalCount = entity.TotalCount;
            return dt;
        }
        #endregion
    }
}
